var express = require('express');
var router = express.Router();
const { add,getAll,getOne,del } = require("../api/labels.js")
/* GET users listing. */

//新增父类型
router.post('/add', async function (req, res, next) {
  const { title,_id} = req.body;
  // 将新增父类型添加到类型数据库内
  const data = await add({title,_id});
  console.log(data);
  const status = true;
  // 判断父类型是否添加成功
  if (data) {
    res.send(status);
  } else {
    status = false;
    res.send(status);
  }

});

// 获取父类型数据
// 和页面相关的操作
router.get('/getAll', async function (req, res, next) {
  const { curPage, eachPage } = req.query;
  const data = await getAll({ curPage, eachPage });
  res.send(data);
});

// 获取_id对应父类型数据
router.get('/getOne', async function (req, res, next) {
  const { _id } = req.query;
  console.log(_id);
  const data = await getOne({ _id });
  res.send(data);
});

// 删除id对应子类型
router.delete('/del', async function (req, res, next) {
    const {labelId, _id}=req.query;
    console.log(labelId);
    const data = await del({ _id,labelId });
    res.send(data);
  });

module.exports = router;
